<?php
namespace Home\Controller;
// use Think\Controller;
// use Think\Verify();


class IndexController extends EmptyController {
    
    public function index(){
        //实例化goods表
        $goods = D('goods');
        //查询热门商品
        $hot = $goods->goods_hot();
        //分配数据
        $this->assign('hot',$hot);
        //查询猜你喜欢
        $like = $goods->goods_like2();
        $this->assign('like',$like);
        //查询手机类的商品
        $phone = $goods->goods_phone();
        // dump($phone);
        $this->assign('phone',$phone['phone']);
        $this->assign('name1',$phone['name']);

        //查询电脑类商品
        $computer = $goods->goods_computer();
        $this->assign('computer',$computer['computer']);
        $this->assign('name2',$computer['name']);

        //查询智能家居类商品
        $smart = $goods->goods_smart();
        // dump($smart['smart']);
        $this->assign('smart',$smart['smart']);
        $this->assign('name',$smart['name']);
        //查询手机配件类商品
        $acc = $goods->goods_acc();
        // dump($smart['smart']);
        $this->assign('acc',$acc['acc']);
        $this->assign('name3',$acc['name']);
        //轮播图查询--1号广告位
        $advs = D('advs');
        $advs_one = $advs->advs_one();
        // dump($advs_one);
        $this->assign('advs_one',$advs_one);
        $advs_two = $advs->advs_two();
        // dump($advs_one);
        $this->assign('advs_two',$advs_two);

        //首页分类查询--查询type表
        $this->type_secl();
        //顶部判断，用户是否登录
        $username = session('user');
        
        $this->assign('username',$username['username']);

        //友情链接
        $this->link_s();
        //导航栏
        $this->bar();
        //首页购物车
        //判断是否有触发ajax
        $user = I('get.user');
        // echo $user;
         if($user){
            // echo "dddd";
            $buycar = D('buycar');
            $buycar_l = $buycar->selc();

            //获取当前用户登录id
            $userid = session('user')['id'];
            $this->assign('bc_l',$buycar_l['list']);
            $this->assign('total',$buycar_l['total']);
            $this->assign('userid',$userid);

         }

        //===添加新闻===================================================================
        $news = M('news');
        $newslist = $news->order('addtime desc')->select();
        $this->assign('news',$newslist);


        $this->display(); 
    }
    //首页分类查询方法
    public function type_secl(){
       $type = D('type');
       $t_list = $type->type_sec();
       $this->assign('t_list',$t_list);
    }
    //首页友链查询方法
    public function link_s(){
        $links = D('links');
        $link = $links->links_sec();
        // dump($list);
        $this->assign('link',$link);
    }
    //输出导航栏
    public function bar(){
        $type = D('type');
        $t_bar = $type->bar_sec();
        $this->assign('bar',$t_bar);
    }
    //执行退出
    public function tuichu(){
        session(null);
        $this->redirect('Home/login/index');
    }
}